#include "lolevel.h"
#include "platform.h"
#include "core.h"

static long *nrflag = (long*)0xB918;

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) sub_FFE72574_my(long p)
{
    asm volatile (
								"STMFD   SP!, {R4,LR}\n"
								"MOV     R4, R0\n"
								"SUB     SP, SP, #0xC\n"
								"BL      sub_FFE72F9C\n"
								"MVN     R1, #0\n"						//differnt from dump but synced wit a560
								"BL      sub_FFE82480\n"
								"MOV     R0, #0x8A\n"
								"ADD     R1, SP, #4\n"				//14-10
								"MOV     R2, #4\n"
								"BL      sub_FFC0B7C4\n"
								"TST     R0, #1\n"
								"BEQ     loc_FFE725B4\n"
								"MOV     R1, #0x1D0\n"
								"LDR     R0, =0xFFE723F8\n"
								"ADD     R1, R1, #2\n"
								"BL      sub_FFE8FB40\n"
	"loc_FFE725B4:\n"
								"LDR     R3, =0x9DDC0\n"
								"LDR     R2, =0x9DE80\n"
								"LDR     R0, [R3,#0x74]\n"
								"LDRSH   R1, [R2,#0xE]\n"
								"BL      sub_FFDD28E0\n"
								"MOV     R0, R4\n"
								"BL      sub_FFE7237C\n"
                                "BL      wait_until_remote_button_is_released\n"
								"BL      capt_seq_hook_set_nr\n" // +
								"LDR     R3, =0xB91C\n"
								"LDR     R0, [R3]\n"

                "B       sub_FFE725D8\n"  // ---> jump to end of function in ROM
    );
}

void __attribute__((naked,noinline)) sub_FFE6F5FC_my(long p)
{
    asm volatile (
								"STMFD   SP!, {R4,LR}\n"
								"LDR     R4, [R0,#0xC]\n"
								"LDR     R3, [R4,#8]\n"
								"ORR     R3, R3, #1\n"
								"STR     R3, [R4,#8]\n"
								"MOV     R0, #0xC\n"
								"BL      sub_FFE79254\n"
								"TST     R0, #1\n"
								"MOV     R0, #1\n"
								"MOV     R2, R4\n"
								"MOV     R1, R0\n"
								"BEQ     loc_FFE6F640\n"
								"LDR     R3, [R4,#8]\n"
								"ORR     R3, R3, #0x40000000\n"
								"STR     R3, [R4,#8]\n"
								"LDMFD   SP!, {R4,LR}\n"
								"B       sub_FFE6DEB0\n"
"loc_FFE6F640:\n"
								"BL      sub_FFE70098\n"
								"MOV     R0, R4\n"
								"BL      sub_FFE710CC\n"
								"TST     R0, #1\n"
								"MOV     R2, R4\n"
								"MOV     R1, #1\n"
								"BEQ     loc_FFE6F664\n"
								"LDMFD   SP!, {R4,LR}\n"
								"B       sub_FFE6DEB0\n"
"loc_FFE6F664:\n"
								"BL      sub_FFC15B10\n"
								"BL      sub_FFC0B9C0\n"
								"STR     R0, [R4,#0x14]\n"
								"MOV     R0, R4\n"
								"BL      sub_FFE7245C\n"
								"BL      sub_FFE72E08\n"
								"MOV     R0, R4\n"
								"BL      sub_FFE72574_my\n"			//------->
								"BL      capt_seq_hook_raw_here\n"  // +
								"MOV     R1, #1\n"
								"MOV     R2, R4\n"
								"BL      sub_FFE6DEB0\n"
								"BL      sub_FFE728A8\n"
								"CMP     R0, #0\n"
								"LDRNE   R3, [R4,#8]\n"
								"ORRNE   R3, R3, #0x2000\n"
								"STRNE   R3, [R4,#8]\n"
								"LDMFD   SP!, {R4,PC}\n"
    );
}

void __attribute__((naked,noinline)) capt_seq_task()
{
	asm volatile (
								"STMFD   SP!, {R4,LR}\n"
								"SUB     SP, SP, #4\n"
								"MOV     R4, SP\n"
								"B       loc_FFE6FB6C\n"
"loc_FFE6FA10:\n"
								"LDR     R2, [SP]\n"
								"LDR     R3, [R2]\n"
								"MOV     R0, R2\n"
								"CMP     R3, #0x15\n"
								"LDRLS   PC, [PC,R3,LSL#2]\n"
								"B       loc_FFE6FB40\n"
								".long loc_FFE6FA80\n"
								".long loc_FFE6FA8C\n"
								".long loc_FFE6FA94\n"
								".long loc_FFE6FAA8\n"
								".long loc_FFE6FAA0\n"
								".long loc_FFE6FAB0\n"
								".long loc_FFE6FAB8\n"
								".long loc_FFE6FAC4\n"
								".long loc_FFE6FACC\n"
								".long loc_FFE6FAD8\n"
								".long loc_FFE6FAE0\n"
								".long loc_FFE6FAE8\n"
								".long loc_FFE6FAF0\n"
								".long loc_FFE6FAF8\n"
								".long loc_FFE6FB00\n"
								".long loc_FFE6FB0C\n"
								".long loc_FFE6FB14\n"
								".long loc_FFE6FB1C\n"
								".long loc_FFE6FB24\n"
								".long loc_FFE6FB30\n"
								".long loc_FFE6FB38\n"
								".long loc_FFE6FB54\n"
"loc_FFE6FA80:\n"
								
								"BL      sub_FFE700AC\n"
								"BL      shooting_expo_param_override\n"   // +
								"BL      sub_FFE6D9A0\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FA8C:\n"
								
								"BL      sub_FFE6F5FC_my\n"  //--------->
								"B       loc_FFE6FB50\n"
"loc_FFE6FA94:\n"
								
								"MOV     R0, #1\n"
								"BL      sub_FFE70280\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FAA0:\n"                            
								
								"BL      sub_FFE6FC50\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FAA8:\n"
								
								"BL      sub_FFE70078\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FAB0:\n"
								
								"BL      sub_FFE70088\n"   
								"B       loc_FFE6FB50\n"
"loc_FFE6FAB8:\n"
								
								"BL      sub_FFE70190\n"   
								"BL      sub_FFE6D9A0\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FAC4:\n"
								
								"BL      sub_FFE6F70C\n"   
								"B       loc_FFE6FB50\n"
"loc_FFE6FACC:\n"
								
								"BL      sub_FFE701F4\n"   
								"BL      sub_FFE6D9A0\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FAD8:\n"
								
								"BL      sub_FFE70078\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FAE0:\n"
								
								"BL      sub_FFE717E0\n"   
								"B       loc_FFE6FB50\n"
"loc_FFE6FAE8:\n"
								
								"BL      sub_FFE719AC\n"   
								"B       loc_FFE6FB50\n"
"loc_FFE6FAF0:\n"
								
								"BL      sub_FFE71A40\n"   
								"B       loc_FFE6FB50\n"
"loc_FFE6FAF8:\n"
								
								"BL      sub_FFE71B3C\n"   
								"B       loc_FFE6FB50\n"
"loc_FFE6FB00:\n"
								
								"MOV     R0, #0\n"   
								"BL      sub_FFE71DA8\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FB0C:\n"
								
								"BL      sub_FFE71F60\n"  
								"B       loc_FFE6FB50\n"
"loc_FFE6FB14:\n"
								
								"BL      sub_FFE71FF4\n"   
								"B       loc_FFE6FB50\n"
"loc_FFE6FB1C:\n"
								
								"BL      sub_FFE720B0\n"   
								"B       loc_FFE6FB50\n"
"loc_FFE6FB24:\n"

								"BL      sub_FFE703D4\n"   
								"BL      sub_FFE6F520\n"
								"B       loc_FFE6FB50\n"
"loc_FFE6FB30:\n"

								"BL      sub_FFE71C7C\n"  
								"B       loc_FFE6FB50\n"
"loc_FFE6FB38:\n"

								"BL      sub_FFE71CD8\n" 
								"B       loc_FFE6FB50\n"
"loc_FFE6FB40:\n"

								"MOV     R1, #0x4C0\n"   
								"LDR     R0, =0xFFE6F37C\n"
								"ADD     R1, R1, #0xE\n"
								"BL      sub_FFE8FB40\n"
"loc_FFE6FB50:\n"

								"LDR     R2, [SP]\n"
"loc_FFE6FB54:\n"

								"LDR     R3, =0x78070\n"
								"LDR     R1, [R2,#4]\n"
								"LDR     R0, [R3]\n"
								"BL      sub_FFE822E4\n"
								"LDR     R0, [SP]\n"
								"BL      sub_FFE6F3FC\n"
"loc_FFE6FB6C:\n"
								"LDR     R3, =0x78074\n"
								"MOV     R1, R4\n"
								"LDR     R0, [R3]\n"
								"MOV     R2, #0\n"
								"BL      sub_FFE829FC\n"
								"TST     R0, #1\n"
								"BEQ     loc_FFE6FA10\n"
								"LDR     R0, =0xFFE6F37C\n"
								"MOV     R1, #0x400\n"
								"BL      sub_FFE8FB40\n"
								"BL      sub_FFE83FC0\n"
								"ADD     SP, SP, #4\n"
								"LDMFD   SP!, {R4,PC}\n"

	);
}


/*************************************************************/
void __attribute__((naked,noinline)) exp_drv_task(){
 asm volatile(
                 "STMFD   SP!, {R4-R8,LR}\n"
                 "SUB     SP, SP, #0x20\n"
                 "ADD     R7, SP, #4\n"
                 "B       loc_FFD0FBD0\n"
 "loc_FFD0F6DC:\n"
                 "CMP     R2, #0x22\n"
                 "BNE     loc_FFD0F6F4\n"
                 "LDR     R0, [R12,#0x8C]\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R12,#0x88]\n"
                 "B       loc_FFD0F758\n"
 "loc_FFD0F6F4:\n"
                 "CMP     R2, #0x1D\n"
                 "BNE     loc_FFD0F708\n"
                 "MOV     R0, R12\n"
                 "BL      sub_FFD0F59C\n"
                 "B       loc_FFD0F748\n"
 "loc_FFD0F708:\n"
                 "CMP     R2, #0x1E\n"
                 "BNE     loc_FFD0F71C\n"
                 "MOV     R0, R12\n"
                 "BL      sub_FFD0F5F8\n"
                 "B       loc_FFD0F748\n"
 "loc_FFD0F71C:\n"
                 "SUB     R3, R2, #0x1F\n"
                 "CMP     R3, #1\n"
                 "BHI     loc_FFD0F734\n"
                 "MOV     R0, R12\n"
                 "BL      sub_FFD0F654\n"
                 "B       loc_FFD0F748\n"
 "loc_FFD0F734:\n"
                 "CMP     R2, #0x21\n"
                 "BNE     loc_FFD0F764\n"
                 "BL      sub_FFCD8804\n"
                 "BL      sub_FFCDB93C\n"
                 "BL      sub_FFCDAB74\n"
 "loc_FFD0F748:\n"
                 "LDR     R3, [SP,#4]\n"
                 "LDR     R0, [R3,#0x8C]\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R3,#0x88]\n"
 "loc_FFD0F758:\n"
                 "LDR     R0, [SP,#4]\n"
                 "BL      sub_FFD0B268\n"
                 "B       loc_FFD0FBD0\n"
 "loc_FFD0F764:\n"
                 "CMP     R2, #0xD\n"
                 "MOV     R8, #1\n"
                 "BNE     loc_FFD0F7D4\n"
                 "LDR     R1, [R12,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R1, R12, R1,LSL#2\n"
                 "ADD     R6, SP, #0x14\n"
                 "SUB     R1, R1, #8\n"
                 "MOV     R2, #0xC\n"
                 "MOV     R0, R6\n"
                 "BL      sub_FFCC037C\n"
                 "LDR     R0, [SP,#4]\n"
                 "BL      sub_FFD0DBA0\n"
                 "LDR     R3, [SP,#4]\n"
                 "LDR     R1, [R3,#0x7C]\n"
                 "LDR     R2, [R3,#0x8C]\n"
                 "ADD     R0, R3, #4\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R3,#0x88]\n"
                 "LDR     R0, [SP,#4]\n"
                 "BL      sub_FFD0DE70\n"
                 "LDR     R3, [SP,#4]\n"
                 "ADD     R0, R3, #4\n"
                 "LDR     R1, [R3,#0x7C]\n"
                 "LDR     R2, [R3,#0x94]\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R3,#0x90]\n"
                 "B       loc_FFD0FB24\n"
 "loc_FFD0F7D4:\n"
                 "SUB     R3, R2, #0xE\n"
                 "CMP     R3, #1\n"
                 "BHI     loc_FFD0F890\n"
                 "ADD     R6, SP, #0x14\n"
                 "ADD     R5, SP, #8\n"
                 "MOV     R0, R12\n"
                 "MOV     R1, R6\n"
                 "MOV     R2, R5\n"
                 "BL      sub_FFD0DF64\n"
                 "MOV     R4, R0\n"
                 "CMP     R4, #5\n"
                 "CMPNE   R4, #1\n"
                 "BNE     loc_FFD0F828\n"
                 "LDR     R12, [SP,#4]\n"
                 "MOV     R0, R5\n"
                 "LDR     R1, [R12,#0x7C]\n"
                 "MOV     R2, R4\n"
                 "LDR     R3, [R12,#0x8C]\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R12,#0x88]\n"
                 "B       loc_FFD0F860\n"
 "loc_FFD0F828:\n"
                 "CMP     R4, #6\n"
                 "CMPNE   R4, #2\n"
                 "BNE     loc_FFD0F870\n"
                 "LDR     R12, [SP,#4]\n"
                 "MOV     R0, R5\n"
                 "MOV     R1, R8\n"
                 "MOV     R2, R4\n"
                 "LDR     R3, [R12,#0x8C]\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R12,#0x88]\n"
                 "MOV     R1, R6\n"
                 "LDR     R0, [SP,#4]\n"
                 "MOV     R2, R5\n"
                 "BL      sub_FFD0F1FC\n"
 "loc_FFD0F860:\n"
                 "MOV     R1, R4\n"
                 "LDR     R0, [SP,#4]\n"
                 "BL      sub_FFD0F530\n"
                 "B       loc_FFD0FB24\n"
 "loc_FFD0F870:\n"
                 "LDR     R12, [SP,#4]\n"
                 "MOV     R2, R4\n"
                 "ADD     R0, R12, #4\n"
                 "LDR     R1, [R12,#0x7C]\n"
                 "LDR     R3, [R12,#0x8C]\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R12,#0x88]\n"
                 "B       loc_FFD0FB24\n"
 "loc_FFD0F890:\n"
                 "SUB     R3, R2, #0x19\n"
                 "CMP     R3, #1\n"
                 "BHI     loc_FFD0F8E8\n"
                 "LDR     R1, [R12,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R1, R12, R1,LSL#2\n"
                 "ADD     R6, SP, #0x14\n"
                 "SUB     R1, R1, #8\n"
                 "MOV     R2, #0xC\n"
                 "MOV     R0, R6\n"
                 "BL      sub_FFCC037C\n"
                 "LDR     R0, [SP,#4]\n"
                 "BL      sub_FFD0D050\n"
                 "LDR     R3, [SP,#4]\n"
                 "ADD     R0, R3, #4\n"
                 "LDR     R1, [R3,#0x7C]\n"
                 "LDR     R2, [R3,#0x8C]\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R3,#0x88]\n"
                 "LDR     R0, [SP,#4]\n"
                 "BL      sub_FFD0D370\n"
                 "B       loc_FFD0FB24\n"
 "loc_FFD0F8E8:\n"
                 "ADD     R6, SP, #0x14\n"
                 "ADD     R1, R12, #4\n"
                 "MOV     R2, #0xC\n"
                 "MOV     R0, R6\n"
                 "BL      sub_FFCC037C\n"
                 "LDR     R12, [SP,#4]\n"
                 "LDR     R3, [R12]\n"
                 "MOV     R2, R12\n"
                 "CMP     R3, #0x1C\n"
                 "LDRLS   PC, [PC,R3,LSL#2]\n"
                 "B       loc_FFD0FB10\n"
                 ".long loc_FFD0F988\n"
                 ".long loc_FFD0F994\n"
                 ".long loc_FFD0F9A0\n"
                 ".long loc_FFD0F9A0\n"
                 ".long loc_FFD0F988\n"
                 ".long loc_FFD0F994\n"
                 ".long loc_FFD0F9A0\n"
                 ".long loc_FFD0F9A0\n"
                 ".long loc_FFD0F9C4\n"
                 ".long loc_FFD0F9C4\n"
                 ".long loc_FFD0FAE4\n"
                 ".long loc_FFD0FAF0\n"
                 ".long loc_FFD0FB00\n"
                 ".long loc_FFD0FB10\n"
                 ".long loc_FFD0FB10\n"
                 ".long loc_FFD0FB10\n"
                 ".long loc_FFD0F9AC\n"
                 ".long loc_FFD0F9B8\n"
                 ".long loc_FFD0F9D4\n"
                 ".long loc_FFD0F9E0\n"
                 ".long loc_FFD0FA18\n"
                 ".long loc_FFD0FA50\n"
                 ".long loc_FFD0FA88\n"
                 ".long loc_FFD0FAC0\n"
                 ".long loc_FFD0FAC0\n"
                 ".long loc_FFD0FB10\n"
                 ".long loc_FFD0FB10\n"
                 ".long loc_FFD0FACC\n"
                 ".long loc_FFD0FAD8\n"
 "loc_FFD0F988:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0BA58\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0F994:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0BCF8\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0F9A0:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0BF6C\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0F9AC:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0C264\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0F9B8:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0C4C8\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0F9C4:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0C6CC_my\n"  //------------->
                 "MOV     R8, #0\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0F9D4:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0C82C\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0F9E0:\n"
                 "LDRH    R1, [R2,#4]\n"
                 "LDR     R3, =0x1C750\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R3,#6]\n"
                 "STRH    R1, [SP,#0x1A]\n"
                 "LDRH    R1, [R3,#2]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R3, [R3,#4]\n"
                 "STRH    R3, [SP,#0x18]\n"
                 "MOV     R0, R2\n"
                 "LDRH    R2, [R2,#0xC]\n"
                 "STRH    R2, [SP,#0x1C]\n"
                 "BL      sub_FFD0CB24\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FA18:\n"
                 "MOV     R0, R2\n"
                 "LDRH    R2, [R2,#4]\n"
                 "LDR     R3, =0x1C750\n"
                 "STRH    R2, [SP,#0x14]\n"
                 "LDRH    R2, [R3,#8]\n"
                 "STRH    R2, [SP,#0x1C]\n"
                 "LDRH    R1, [R3,#2]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R2, [R3,#4]\n"
                 "STRH    R2, [SP,#0x18]\n"
                 "LDRH    R3, [R3,#6]\n"
                 "STRH    R3, [SP,#0x1A]\n"
                 "BL      sub_FFD0CC48\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FA50:\n"
                 "LDR     R3, =0x1C750\n"
                 "LDRH    R1, [R3]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "MOV     R0, R2\n"
                 "LDRH    R2, [R2,#6]\n"
                 "STRH    R2, [SP,#0x16]\n"
                 "LDRH    R2, [R3,#8]\n"
                 "STRH    R2, [SP,#0x1C]\n"
                 "LDRH    R1, [R3,#4]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "LDRH    R3, [R3,#6]\n"
                 "STRH    R3, [SP,#0x1A]\n"
                 "BL      sub_FFD0CD0C\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FA88:\n"
                 "LDR     R3, =0x1C750\n"
                 "LDRH    R1, [R3,#6]\n"
                 "STRH    R1, [SP,#0x1A]\n"
                 "LDRH    R1, [R3]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R3,#2]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R3, [R3,#4]\n"
                 "STRH    R3, [SP,#0x18]\n"
                 "MOV     R0, R2\n"
                 "LDRH    R2, [R2,#0xC]\n"
                 "STRH    R2, [SP,#0x1C]\n"
                 "BL      sub_FFD0CDC4\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FAC0:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0CE70\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FACC:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0D4C0\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FAD8:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0D6BC\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FAE4:\n"
                 "MOV     R0, R2\n"
                 "BL      sub_FFD0D878\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FAF0:\n"
                 "MOV     R0, R2\n"
                 "MOV     R1, #0\n"
                 "BL      sub_FFD0DA60\n"
                 "B       loc_FFD0FB0C\n"
 "loc_FFD0FB00:\n"
                 "MOV     R0, R2\n"
                 "MOV     R1, #1\n"
                 "BL      sub_FFD0DA60\n"
 "loc_FFD0FB0C:\n"
                 "LDR     R12, [SP,#4]\n"
 "loc_FFD0FB10:\n"
                 "ADD     R0, R12, #4\n"
                 "LDR     R1, [R12,#0x7C]\n"
                 "LDR     R2, [R12,#0x8C]\n"
                 "MOV     LR, PC\n"
                 "LDR     PC, [R12,#0x88]\n"
 "loc_FFD0FB24:\n"
                 "CMP     R8, #1\n"
                 "BNE     loc_FFD0FB4C\n"
                 "LDR     R1, [SP,#4]\n"
                 "LDR     R3, [R1,#0x7C]\n"
                 "ADD     R3, R3, R3,LSL#1\n"
                 "ADD     R1, R1, R3,LSL#2\n"
                 "MOV     R0, R6\n"
                 "SUB     R1, R1, #8\n"
                 "BL      sub_FFD0B7D0\n"
                 "B       loc_FFD0FBC8\n"
 "loc_FFD0FB4C:\n"
                 "LDR     R3, [SP,#4]\n"
                 "LDR     R2, [R3]\n"
                 "CMP     R2, #9\n"
                 "BNE     loc_FFD0FB94\n"
                 "MOV     R4, #0\n"
                 "MOV     R1, #1\n"
                 "MOV     R2, R1\n"
                 "MOV     R3, R1\n"
                 "MOV     R0, R4\n"
                 "STR     R4, [SP]\n"
                 "BL      sub_FFD0B724\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, R4\n"
                 "MOV     R2, R1\n"
                 "MOV     R3, R1\n"
                 "STR     R4, [SP]\n"
                 "BL      sub_FFD0B8AC\n"
                 "B       loc_FFD0FBC8\n"
 "loc_FFD0FB94:\n"
                 "MOV     R4, #1\n"
                 "MOV     R0, R4\n"
                 "MOV     R1, R4\n"
                 "MOV     R2, R4\n"
                 "MOV     R3, R4\n"
                 "STR     R4, [SP]\n"
                 "BL      sub_FFD0B724\n"
                 "MOV     R0, R4\n"
                 "MOV     R1, R0\n"
                 "MOV     R2, R0\n"
                 "MOV     R3, R0\n"
                 "STR     R4, [SP]\n"
                 "BL      sub_FFD0B8AC\n"
 "loc_FFD0FBC8:\n"
                 "LDR     R0, [SP,#4]\n"
                 "BL      sub_FFD0B268\n"
 "loc_FFD0FBD0:\n"
                 "LDR     R3, =0x1C744\n"
                 "MOV     R2, #0\n"
                 "LDR     R0, [R3]\n"
                 "MOV     R1, R7\n"
                 "BL      sub_FFE829FC\n"
                 "LDR     R12, [SP,#4]\n"
                 "LDR     R2, [R12]\n"
                 "CMP     R2, #0x23\n"
                 "BNE     loc_FFD0F6DC\n"
                 "MOV     R0, R12\n"
                 "BL      sub_FFD0B268\n"
                 "LDR     R3, =0x1C740\n"
                 "MOV     R1, #1\n"
                 "LDR     R0, [R3]\n"
                 "BL      sub_FFE822E4\n"
                 "BL      sub_FFE83FC0\n"
                 "ADD     SP, SP, #0x20\n"
                 "LDMFD   SP!, {R4-R8,PC}\n"
 );
}

void __attribute__((naked,noinline)) sub_FFD0C6CC_my(){
 asm volatile(
                 "STMFD   SP!, {R4-R6,LR}\n"
                 "LDR     R3, =0x1C740\n"
                 "MOV     R4, R0\n"
                 "MOV     R1, #0x3E\n"
                 "LDR     R0, [R3]\n"
                 "BL      sub_FFE82480\n"
                 "MOV     R1, #0\n"
                 "LDRSH   R0, [R4,#4]\n"
                 "BL      sub_FFD0B398\n"
                 "MOV     R6, R0\n"
                 "LDRSH   R0, [R4,#6]\n"
                 "BL      sub_FFD0B464\n"
                 "LDRSH   R0, [R4,#8]\n"
                 "BL      sub_FFD0B500\n"
                 "LDRSH   R0, [R4,#0xA]\n"
                 "BL      sub_FFD0B59C\n"
                 "LDRSH   R0, [R4,#0xC]\n"
                 "BL      sub_FFD0B638\n"
                 "LDR     R3, [R4]\n"
                 "CMP     R3, #9\n"
                 "MOV     R5, R0\n"
                 "MOVEQ   R5, #0\n"
                 "MOVEQ   R6, R5\n"
                 "CMP     R6, #1\n"
                 "BNE     loc_FFD0C750\n"
                 "MOV     R2, #2\n"
                 "LDRSH   R0, [R4,#4]\n"
                 "LDR     R1, =0xFFD0B2B8\n"
                 "BL      sub_FFE49ECC\n"
                 "LDR     R2, =0x1C780\n"
                 "MOV     R3, #0\n"
                 "STR     R3, [R2]\n"
                 "B       loc_FFD0C754\n"
 "loc_FFD0C750:\n"
                 "BL      sub_FFD0B6D4\n"
 "loc_FFD0C754:\n"
                 "STRH    R0, [R4,#4]\n"
                 "CMP     R5, #1\n"
                 "BNE     loc_FFD0C774\n"
                 "LDRSH   R0, [R4,#0xC]\n"
                 "LDR     R1, =0xFFD0B37C\n"
                 "MOV     R2, #0x20\n"
                 "BL      sub_FFD0B9F8\n"
                 "B       loc_FFD0C778\n"
 "loc_FFD0C774:\n"
                 "BL      sub_FFD0B714\n"
 "loc_FFD0C778:\n"
                 "STRH    R0, [R4,#0xC]\n"
                 "LDRSH   R0, [R4,#6]\n"
                 "BL      sub_FFCD8480_my\n"  //------------>
                 "LDRSH   R0, [R4,#8]\n"
                 "MOV     R1, #1\n"
                 "BL      sub_FFCDA734\n"
                 "ADD     R0, R4, #8\n"
                 "MOV     R1, #0\n"
                 "BL      sub_FFCDA7F4\n"
                 "LDRSH   R0, [R4,#0xE]\n"
                 "BL      sub_FFCFA050\n"
                 "CMP     R6, #1\n"
                 "BNE     loc_FFD0C7DC\n"
                 "LDR     R3, =0x1C740\n"
                 "MOV     R2, #0xBB0\n"
                 "LDR     R0, [R3]\n"
                 "MOV     R1, #2\n"
                 "ADD     R2, R2, #8\n"
                 "BL      sub_FFE822D4\n"
                 "TST     R0, #1\n"
                 "BEQ     loc_FFD0C7DC\n"
                 "MOV     R1, #0x460\n"
                 "LDR     R0, =0xFFD0B214\n"
                 "ADD     R1, R1, #2\n"
                 "BL      sub_FFE8FB40\n"
 "loc_FFD0C7DC:\n"
                 "CMP     R5, #1\n"
                 "LDMNEFD SP!, {R4-R6,PC}\n"
                 "LDR     R3, =0x1C740\n"
                 "MOV     R2, #0xBB0\n"
                 "LDR     R0, [R3]\n"
                 "MOV     R1, #0x20\n"
                 "ADD     R2, R2, #8\n"
                 "BL      sub_FFE822D4\n"
                 "TST     R0, #1\n"
                 "LDMEQFD SP!, {R4-R6,PC}\n"
                 "MOV     R1, #0x460\n"
                 "LDR     R0, =0xFFD0B214\n"
                 "ADD     R1, R1, #7\n"
                 "LDMFD   SP!, {R4-R6,LR}\n"
                 "B       sub_FFE8FB40\n"
 );
}


void __attribute__((naked,noinline)) sub_FFCD8480_my(){
 asm volatile(
                 "STMFD   SP!, {R4,LR}\n"
                 "LDR     R3, =0x5884\n"
                 "LDR     R2, [R3]\n"
                 "MOV     R1, #0x168\n"
                 "MOV     R3, R0,LSL#16\n"
                 "CMP     R2, #1\n"
                 "ADD     R1, R1, #3\n"
                 "LDR     R0, =0xFFCD7C9C\n"
                 "MOV     R4, R3,ASR#16\n"
                 "BEQ     loc_FFCD84AC\n"
                 "BL      sub_FFE8FB40\n"
 "loc_FFCD84AC:\n"
                 "MOV     R1, #0x170\n"
                 "CMN     R4, #0xC00\n"
                 "LDR     R3, =0x10356\n"
                 "LDR     R0, =0xFFCD7C9C\n"
                 "ADD     R1, R1, #1\n"
                 "LDREQSH R4, [R3]\n"
                 "LDRNE   R3, =0x10356\n"
                 "CMN     R4, #0xC00\n"
                 "STRH    R4, [R3]\n"
                 "BNE     loc_FFCD84D8\n"
                 "BL      sub_FFE8FB40\n"
 "loc_FFCD84D8:\n"
                 "MOV     R0, R4\n"
             //  "BL      sub_FFCD95D0\n"  // -
                 "BL      apex2us\n"       // +
                 "MOV     R4, R0\n"
                 "BL      sub_FFD5AB78\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FFD6FF2C\n"
                 "MOV     R1, #0x174\n"
                 "TST     R0, #1\n"
                 "ADD     R1, R1, #2\n"
                 "LDR     R0, =0xFFCD7C9C\n"
                 "LDMEQFD SP!, {R4,PC}\n"
                 "LDMFD   SP!, {R4,LR}\n"
                 "B       sub_FFE8FB40\n"
 );
}

